import { _decorator, AudioClip, Component, director, log, Node, ResolutionPolicy, sys, view } from 'cc';
const { ccclass, property, executionOrder } = _decorator;

import { Consts } from "../Data/Consts";
import { GameData } from "../Data/GameData";
import GameStorage from "../Data/GameStorage";
import SS_AssetsManager from "../Manager/SS_AssetsManager";
import { bdlMgr } from "../Manager/SS_BundleManager";
import SS_UIManager from "../Manager/SS_UIManager";
import UserDataMgr from "../Manager/UserDataMgr";
import TAComponent from "../sdk/TAComponent";
import StartPanel from "../UI/StartPanel";
import { SS_AudioManager } from '../Manager/SS_AudioManager';
import { SS_Settings } from '../Data/SS_Settings';

// // 慢一点执行
@ccclass('MainScene')
@executionOrder(101)
export default class MainScene extends Component {
    static Instance: MainScene;

    @property(Node)
    public UI: Node | null = null;

    async onLoad() {
        MainScene.Instance = this;

        // console.log("MainScene----------------");

        // {
        //     // 适配屏幕
        //     if (sys.isBrowser) {
        //         // view.setDesignResolutionSize(720, 1600, ResolutionPolicy.SHOW_ALL)
        //         view.setDesignResolutionSize(720, 1600, ResolutionPolicy.FIXED_HEIGHT)
        //         // view.setDesignResolutionSize(720, 1600, ResolutionPolicy.EXACT_FIT)
        //         view.emit("canvas-resize")
        //     }
        // }


        SS_UIManager.Instance.ResetUINode();

        // TAComponent.Init();

        // UserDataMgr.Instance.LoginPlatform(1, false);

        // TAComponent.SendEvent(Consts.埋点事件.loading开始, {});

        director.preloadScene("GameScene");

        // if (GameData.isFirstEnterMainScene) {
        // GameData.isFirstEnterMainScene = false;

        GameStorage.initData();

        StartPanel.Instance.main.active = false;
        StartPanel.Instance.loading();

        await SS_AssetsManager.Load_All();

        // }

        // TAComponent.SendEvent(Consts.埋点事件.进入封面, {});


        StartPanel.Instance.ShowOn();

        StartPanel.Instance.ProgressBar.node.active = false;
        StartPanel.Instance.main.active = true;

        SS_Settings.InitSettings()


        // bdlMgr.getRes<AudioClip>(Consts.BundleName.AUDIO, `bgm/游戏封面音乐`, AudioClip).then(async (audio) => {
        //     SS_AudioManager.Instance.play(audio, SS_Settings.curMusicV);
        // });



        StartPanel.Instance.ShowOff();
        StartPanel.Instance.进入管卡();
        // TAComponent.SendEvent(Consts.埋点事件.点击开始游戏, {});
        SS_AudioManager.PlayButtonAudio();
        
    }
}